package hadoop;
import java.io.IOException;
import java.net.InetSocketAddress;

import lucene_ik.Item;
import lucene_ik.json;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.ipc.RPC;
import org.json.JSONException;

public class MyClient {
    
    private MyProtocol proxy;

    public MyClient(String ip,int port){
        InetSocketAddress addr = new InetSocketAddress(ip,port);
        try {
            //proxy = (MyProtocol) RPC.waitForProxy(MyProtocol.class, 1, addr , new Configuration(), 0);
            proxy=(MyProtocol) RPC.waitForProxy(MyProtocol.class, 1, addr, new Configuration());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public void println(String s){
        System.out.println(proxy.println(new Text(s)));
    }
    
//    public void getItem(String s){
//    	
//    	System.out.println(proxy.IndexItem(s));
//    }
    public void getItem(Item item){
    	try {
			String str=json.tojson(item);
			System.out.println(proxy.IndexItem(str));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    }
    
//    public String getSource(){
//    	return 
//    }

    public void close(){
        RPC.stopProxy(proxy);
    }
    

}
